/*! ******************************************************************************
 *
 * Created on 2021年9月25日
 *
 * Copyright(c) YuZhou Big Data Laboratory CO.,Ltd, 2022.  All rights reserved.
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

package org.pentaho.di.ui.core.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.*;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.ui.core.PropsUI;
import org.pentaho.di.ui.core.gui.GUIResource;
import org.pentaho.di.ui.spoon.Spoon;
import org.pentaho.di.ui.trans.step.BaseStepDialog;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;

/**
 * @author tanpeng@yzbdl.ac.cn
 * @version 1.0
 * @date 2022-08-02 11:19
 */
public class VersionDialog extends Dialog {
	private static Class<?> PKG = Spoon.class;

	private String dialogTitle;

	private Button copy;
	private Listener copyCancel;
	private Shell shell;
	private PropsUI props;
	private Text text;

	public VersionDialog(Shell parent, String dialogTitle) {
		super(parent, SWT.NONE);
		props = PropsUI.getInstance();
		this.dialogTitle = dialogTitle;
	}

	protected Shell createShell(Shell parent) {
		return new Shell(parent, SWT.RESIZE | SWT.MAX | SWT.MIN);
	}

	public void open() throws NoSuchAlgorithmException, IOException, Exception {
		Shell parent = getParent();
		Display display = parent.getDisplay();

		shell = createShell(parent);
		shell.setSize(450, 301);
		shell.setImage(GUIResource.getInstance().getImageSpoon());
		props.setLook(shell);

		FormLayout formLayout = new FormLayout();

		shell.setLayout(formLayout);
		shell.setText(dialogTitle);

		// 初始化功能栏
		Composite contentPane = new Composite(shell, SWT.NONE);
		contentPane.setLayout(null);
		FormData fd_contentPane = new FormData();
		fd_contentPane.left = new FormAttachment(0);
		fd_contentPane.right = new FormAttachment(100);
		fd_contentPane.top = new FormAttachment(0);
		contentPane.setLayoutData(fd_contentPane);

		// 初始化底部按钮栏
		Composite buttonsPane = new Composite(shell, SWT.NONE);
		fd_contentPane.bottom = new FormAttachment(0, 183);

		Color grey = new Color(display, 240, 240, 240);
		buttonsPane.setBackground(grey);
		buttonsPane.setLayout(new FormLayout());
		FormData fdButtonsPane = new FormData();
		fdButtonsPane.top = new FormAttachment(100, -39);
		fdButtonsPane.left = new FormAttachment(0, 0);
		fdButtonsPane.right = new FormAttachment(100, 0);
		fdButtonsPane.bottom = new FormAttachment(100, 0);
		buttonsPane.setLayoutData(fdButtonsPane);

		Label surplusTimeLabel = new Label(contentPane, SWT.CENTER);
		surplusTimeLabel.setBounds(199,30, 100, 17);
		surplusTimeLabel.setText(BaseMessages.getString(PKG, "VersionDialog.title"));


		// 设置窗体大小
		BaseStepDialog.setSize(shell, 480, 260, true);
		//parent.setEnabled(false);// 设置父窗体不可操作
		shell.open();
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
	
	
	public void dispose() {
		shell.dispose();
	}
	
	protected void cancel() throws Exception {
		dispose();
	}
	
	
}
